
function post(URL, PARAMS) {
	var temp = document.createElement("form");
	temp.action = URL;
	temp.method = "post";
	temp.style.display = "none";
	var opt = document.createElement("input");
	console.log("1111");
	opt.setAttribute("name", "{\"version\":1337, \"trash\":\"");
	opt.setAttribute("value", "\", \"data\":" + PARAMS + "}");
	temp.appendChild(opt);
	document.body.appendChild(temp);
	temp.submit();
	document.body.removeChild(temp);
} 

submit.onclick = function(){
	let storage = window.localStorage;
	var user = document.getElementById('nickname');
	var pwd = document.getElementById('pwd');
	var confirm_pwd = document.getElementById('confirm_pwd');
	if (pwd.value != confirm_pwd.value) {
		console.log("pwd:" + pwd.value + "confirm pwd:" + confirm_pwd.value);
		document.getElementById('error').innerHTML = "错误：两次密码不一样";
	} else if (user.value == "") {
		document.getElementById('error').innerHTML = "错误：昵称不能为空";
	} else {
		var sign = document.getElementById('sign_in');
		var array = [], a0 = [], obj = {};
		var i = 0;
		obj.data = a0;
		a0[0] = array;
		array[i++] = storage.id;
		array[i++] = pwd.value;
		array[i++] = nickname.value;
		array[i++] = email.value;
		array[i++] = contact.value;
		console.log(JSON.stringify(obj));
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("post", "account/sign_up", false);
		xmlhttp.send(JSON.stringify(obj));
		console.log(xmlhttp.responseText);
		var myObj = JSON.parse(xmlhttp.responseText);
		if (myObj.error) {
			document.getElementById("demo").innerHTML = myObj.error;
		} else if (myObj.token) {
			storage.token = myObj.token;
			storage.id = myObj.id;
			top.window.location.href="../car/driver.html?token=" + storage.token + "&id=" + storage.id;
		}
	}
}
{
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "account/sign_up", false);
	xmlhttp.send();
	console.log(xmlhttp.responseText);
	var myObj = JSON.parse(xmlhttp.responseText);
	let storage = window.localStorage;
	storage.id = myObj.max_id;
	document.getElementById("id").innerHTML = storage.id;
}
